﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Guest.Master" AutoEventWireup="True"
    CodeBehind="List.aspx.cs" Inherits="ScrumLite.WebUx.WorkAreasViews.List" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">

    function encoder(value)
    {
        var result="";
        for (i=0; i<value.toString().length; i++)
        {
            if(value.toString().substring(i,i+3) == "%5C")
            {
                result = result.concat("¿5C¿");
                i=i+2;
            }
            else if (value.toString().substring(i,i+1) == "." )
            {
                result = result.concat("¿punto¿");
            }
            else
            {
                result=result.concat(value.toString().charAt(i));                
            }
        }
        return result;
    }
    function redirectToRequest(name)
    {
        var nameParsed =encoder(name);
        document.location= '<%= Url.Action(new { Action = "Read", Controller = "Requests", Mode = "All", WorkArea = Uri.EscapeUriString("'+nameParsed+'")})%>';
    }
    
    function redirectToDeliverables(name)
    {
        var nameParsed =encoder(name);
        document.location= '<%= Url.Action(new { Action = "ListByWorkArea", Controller = "Deliverables", WorkAreaName = Uri.EscapeUriString("'+nameParsed+'") })%>';
    }
    
    function redirectToEdit(name, id)
    {
        var nameParsed =encoder(name);
        document.location= '<%= Url.Action(new { Action = "Edit", Controller = "WorkAreas", Id ="'+id+'", Name = Uri.EscapeUriString("'+nameParsed+'")})%>'
    }
    </script>

    <h1>
        <%=ViewData.ProjectName%></h1>
    <hr />
    <h2>
        Work Areas</h2>
    <br />
    <div class="actions">
        <%= Html.ActionLink( "New", "New", "WorkAreas" ) %>&nbsp;
    </div>
    <br />
    <div class="formTable">
        <table cellpadding="0" cellspacing="0">
            <tr>
                <th>
                    Work Area
                </th>
                <th>
                    Total Weight
                </th>
                <th>
                    Deliverables
                </th>
                <th>
                    Requests
                </th>
                <th>
                    &nbsp;
                </th>
            </tr>
            <% foreach (ScrumLite.Services.Contracts.WorkAreaWeight wa in ViewData.WorkAreas)
               {%>
            <tr>
                <td>
                    <%=wa.Name%>
                </td>
                <td>
                    <%=wa.Weight%>
                </td>
                <td>
                    <a href="javascript:void(0)" onclick="redirectToDeliverables('<%=Uri.EscapeUriString(wa.Name)%>')">
                        <%= wa.Deliverables.ToString()%>
                    </a>
                </td>
                <td>
                    <a href="javascript:void(0)" onclick="redirectToRequest('<%=Uri.EscapeUriString(wa.Name)%>')">
                        <%= wa.Requests.ToString()%>
                    </a>
                </td>
                <td class="btnEdit">
                    <a href="javascript:void(0)" onclick="redirectToEdit('<%=Uri.EscapeUriString(wa.Name)%>', '<%=wa.Id.ToString()%>')">
                        Edit</a>
                </td>
            </tr>
            <%} %>
        </table>
    </div>
    <br />
    <div class="actions">
        <%= Html.ActionLink( "New", "New", "WorkAreas" ) %>&nbsp;
    </div>
</asp:Content>
